import {LogLanguage} from "../dist/index.js"

// 测试新的TID格式识别
const testCases = [
  // 新的格式：[TID:] [xxx]
  "2024-01-15 10:30:45 [INFO] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Processing request",
  
  // 小写格式：[tid:] [xxx]
  "2024-01-15 10:30:45 [ERROR] [tid:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Error occurred",
  
  // 混合格式：标准TID + 新格式
  "2024-01-15 10:30:45 [WARNING] TID:abc123 [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Warning message",
  
  // 只有新格式
  "2024-01-15 10:30:45 [FATAL] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] Critical error",
  
  // 复杂格式
  "2024-01-15 10:30:45 [INFO] [TID:] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] (com.cn.yft.ora.bank.sby.service.SBYBaseService:70) Processing request with id=\"12345\""
]

console.log("=== 新 TID 格式识别测试 ===")

testCases.forEach((testCase, index) => {
  console.log(`\n测试 ${index + 1}:`)
  console.log(`输入: ${testCase}`)
  
  const tree = LogLanguage.parser.parse(testCase)
  let foundNodes = []
  
  tree.iterate({
    enter: (node) => {
      foundNodes.push({
        name: node.type.name,
        from: node.from,
        to: node.to,
        text: testCase.slice(node.from, node.to)
      })
    }
  })
  
  console.log("识别的节点:")
  foundNodes.forEach(node => {
    console.log(`  - ${node.name}: "${node.text}" (${node.from}-${node.to})`)
  })
  
  // 检查TID相关节点
  const tidNodes = foundNodes.filter(node => 
    node.name.includes('TID') || 
    node.text.includes('fcdfba1a21214a8e97c7d8fd1a8aa287')
  )
  
  if (tidNodes.length > 0) {
    console.log("\n✓ TID 节点识别成功")
    tidNodes.forEach(node => {
      console.log(`  - ${node.name}: "${node.text}"`)
    })
  } else {
    console.log("\n✗ 未找到 TID 节点")
  }
  
  // 检查新的TID格式
  const newTidNodes = foundNodes.filter(node => 
    node.name === 'TIDWithEmptyPrefixExpression'
  )
  
  if (newTidNodes.length > 0) {
    console.log("✓ 新 TID 格式识别成功")
    newTidNodes.forEach(node => {
      console.log(`  - ${node.name}: "${node.text}"`)
    })
  } else {
    console.log("✗ 未找到新 TID 格式")
  }
})
